﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;


namespace CMS.BLL
{
    public class Cruise
    {
        #region Common
        public eCruise Data;

        public Cruise()
        {
            Data = new eCruise();
		}

        ~Cruise()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cCruise objDAL = new cCruise();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cCruise objDAL = new cCruise();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cCruise objInfor = new cCruise(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.CruiseID;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }
        public int UpdatePriority(int CruiseID, int Priority)
        {
            int nResult = 0;
            cCruise objDAL = new cCruise();
            try
            {
                objDAL.LoadByPrimaryKey(CruiseID);
                objDAL.Priority = Priority;

                objDAL.Save();
                nResult = objDAL.CruiseID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        //Update nhung cai ma eCruise Data dang nam giu thong qua cCruise objInfor
        public int Update(int ID)
        {
            int nResult = 0;
            cCruise objInfor = new cCruise();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }
        public int UpdateStatus(int ID, int Status)
        {
            int nResult = 0;
            cCruise objDAL = new cCruise();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Status = Status;
                objDAL.Save();
                nResult = objDAL.CruiseID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        private void MappingData(cCruise objInfor)
        {
            try { objInfor.Content1 = Data.Content1; }
            catch { objInfor.Content1 = ""; }
            try { objInfor.Content2 = Data.Content2; }
            catch { objInfor.Content2 = ""; }
            try { objInfor.Content3 = Data.Content3; }
            catch { objInfor.Content3 = ""; }
            objInfor.CountryID = Data.CountryID;
            objInfor.CruiseDurationID = Data.CruiseDurationID;
         
            try { objInfor.ImageDetail1 = Data.ImageDetail1; }
            catch { objInfor.ImageDetail1 = ""; }
            try { objInfor.ImageDetail2 = Data.ImageDetail2; }
            catch { objInfor.ImageDetail2 = ""; }
            try { objInfor.ImageDetail3 = Data.ImageDetail3; }
            catch { objInfor.ImageDetail3 = ""; }
            try { objInfor.ImageDetail4 = Data.ImageDetail4; }
            catch { objInfor.ImageDetail4 = ""; }
            try { objInfor.ImageDetail5 = Data.ImageDetail5; }
            catch { objInfor.ImageDetail5 = ""; }
            objInfor.Images = Data.Images;
            try { objInfor.InitContent1 = Data.InitContent1; }
            catch { objInfor.InitContent1 = ""; }
            try { objInfor.InitContent2 = Data.InitContent2; }
            catch { objInfor.InitContent2 = ""; }
            try { objInfor.InitContent3 = Data.InitContent3; }
            catch { objInfor.InitContent3 = ""; }
            objInfor.PriceFrom = Data.PriceFrom;
            objInfor.PriceTo = Data.PriceTo;
            objInfor.Priority = Data.Priority;
            objInfor.Status = Data.Status;
            try { objInfor.Title1 = Data.Title1; }
            catch { objInfor.Title1 = ""; }
            try { objInfor.Title2 = Data.Title2; }
            catch { objInfor.Title2 = ""; }
            try { objInfor.Title3 = Data.Title3; }
            catch { objInfor.Title3 = ""; }
            try { objInfor.VideoLink = Data.VideoLink; }
            catch { objInfor.VideoLink = ""; }

            objInfor.CruiseRegion = Data.CruiseRegion;
            objInfor.Type = Data.Type;
            try { objInfor.Content1_2day = Data.Content1_2day; }
            catch { objInfor.Content1_2day = ""; }

            try { objInfor.Content2_2day = Data.Content2_2day; }
            catch { objInfor.Content2_2day = ""; }

            try { objInfor.Content3_2day = Data.Content3_2day; }
            catch { objInfor.Content3_2day = ""; }

            try { objInfor.Content1_3day = Data.Content1_3day; }
            catch { objInfor.Content1_3day = ""; }

            try { objInfor.Content2_3day = Data.Content2_3day; }
            catch { objInfor.Content2_3day = ""; }

            try { objInfor.Content3_3day = Data.Content3_3day; }
            catch { objInfor.Content3_3day = ""; }
            
        }
        private void ConvertData(cCruise objInfor)
        {
            Data.Content1 = objInfor.Content1;
            Data.Content2 = objInfor.Content2;
            Data.Content3 = objInfor.Content3;
            Data.CountryID = objInfor.CountryID;
            Data.CruiseDurationID = objInfor.CruiseDurationID;
         
            Data.ImageDetail1 = objInfor.ImageDetail1;
            Data.ImageDetail2 = objInfor.ImageDetail2;
            Data.ImageDetail3 = objInfor.ImageDetail3;
            Data.ImageDetail4 = objInfor.ImageDetail4;
            Data.ImageDetail5 = objInfor.ImageDetail5;
            Data.Images = objInfor.Images;
            Data.InitContent1 = objInfor.InitContent1;
            Data.InitContent2 = objInfor.InitContent2;
            Data.InitContent3 = objInfor.InitContent3;
            Data.PriceFrom = objInfor.PriceFrom;
            Data.PriceTo = objInfor.PriceTo;
            Data.Priority = objInfor.Priority;
            Data.Status = objInfor.Status;
            Data.Title1 = objInfor.Title1;
            Data.Title2 = objInfor.Title2;
            Data.Title3 = objInfor.Title3;
            Data.VideoLink = objInfor.VideoLink;

            Data.CruiseRegion = objInfor.CruiseRegion;
            Data.Type = objInfor.Type;
            Data.Content1_2day = objInfor.Content1_2day;
            Data.Content2_2day = objInfor.Content2_2day;
            Data.Content3_2day = objInfor.Content3_2day;
            Data.Content1_3day = objInfor.Content1_3day;
            Data.Content2_3day = objInfor.Content2_3day;
            Data.Content3_3day = objInfor.Content3_3day;
        }
        public DataTable Search(int ItemView, int ItemID, int Country, int Region, int Type, int status, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cCruise objDAL = new cCruise();
            tbResult = objDAL.Search(ItemView, ItemID, Country, Region, Type, status, PageIndex, PageSize, ref PageCount);
            return tbResult;
        }
        public DataTable GetALL()
        {
            DataTable tbResult = new DataTable();
            cCruise objDAL = new cCruise();
            tbResult = objDAL.GetALL();
            return tbResult;
        }
       #endregion
    }
}
